/*	ChemicalFormulaParser.java
 *
 *	Copyright (c) Manateem Challenge Group, Zaia Group, and contributors 2010
 *
 *	This file is part of MSGSwingSet ('this project').
 *
 *	This project is free software: you can redistribute it and/or modify it
 *	under the terms of the GNU General Public License as published by the Free
 *	Software Foundation, either version 3 of the License, or (at your option)
 *	any later version.
 *
 *	This project is distributed in the hope that it will be useful, but WITHOUT
 *	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *	FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 *	more details.
 *
 *	You should have received a copy of the GNU General Public License along with
 *	this project. If not, see <http://www.gnu.org/licenses/>.
 */
package edu.bu.manateem.msg.util;

import java.util.HashMap;
import java.util.Map;

/**
 *	<p>
 *	
 *	</p>
 *
 *
 *	@author
 *		Christopher Jacobs
 *
 *	@version
 *		1.0
 *
 *	@changelog
 *		May 14, 2010	- Version 1.0.
 */
public class ChemicalFormulaParser
{
	/*
	 * TYPES
	 */

	/*
	 * CONSTANTS
	 */

	private static final String[] ELEMENTS =
		{
			"H","C","N","O","S"
		};
	
	/*
	 * FIELDS
	 */

	/*
	 * CONSTRUCTORS
	 */

	/*
	 * INITIALIZERS
	 */

	/*
	 * METHODS
	 */

	public static Integer getCount(String element,String formula)
	{
		int count = 0;
		for (int i = formula.indexOf(element); (i <= formula.lastIndexOf(element))
			&& (i >= 0); i = formula.substring(i + 1).indexOf(element))
		{
			System.out.println(i);
		}
		return new Integer(count);
	}
	
	public static void main(String[] args)
	{
		ChemicalFormulaParser.toMap("C6H12O6");
	}
	
	public static Map<String,Integer> toMap(String formula)
	{
		Map<String,Integer> map = new HashMap<String,Integer>();
		
		for (String element : ChemicalFormulaParser.ELEMENTS)
		{
			map.put(element,ChemicalFormulaParser.getCount(element,formula));
			System.out.println(element + " :: " + map.get(element));
		}
		
		return map;
	}
}
